<?php

namespace App\NotificationActions;

use App\Models\Order;

class CartClear implements NotificationActionInterface
{
    public function action($params)
    {
        $order = $this->getModel($params);

        if (empty($order))
            return ;

        $order->items()->delete();
        $order->sumMoney();
        $order->save();
    }

    public function getModel($params)
    {
        /**
         * @var Order $order
         */
        $order = Order::find($params);
        $order->load([
            'items', 'items.goods', 'items.table.tableType', 'items.costRule', 'items.assistantUser',
            'user', 'member', 'store',
        ]);

        return $order;
    }
}
